package io.github.yotta.common.utils.param;

import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.Nullable;


/**
 * @author yotta
 * @date 2022/11/7 20:27
 */
public final class MoreObject {

    private MoreObject() {

    }

    public static <T> T firstNonNull(@Nullable T first, @Nullable T second) {
        if (first != null) {
            return first;
        }
        if (second != null) {
            return second;
        }
        throw new NullPointerException("Both parameters are null");
    }

    public static String firstNoneEmpty(@Nullable String first, @Nullable String second) {
        if (StringUtils.isNoneEmpty(first)) {
            return first;
        }
        if (second != null) {
            return second;
        }
        throw new NullPointerException("Both parameters are null");
    }

    public static String firstNotBlank(@Nullable String first, @Nullable String second) {
        if (StringUtils.isNotBlank(first)) {
            return first;
        }
        if (second != null) {
            return second;
        }
        throw new NullPointerException("Both parameters are null");
    }
}
